// some easy code to do a very simple ramping up - in this scenario if the joystcik is below the "50" threshold - then we cut the power in half to allow for more fine controls at the lower levels - also helps just slightly ramping up at full speed (though not much)

void Base(void)
{
  // Is the joystick moving forward or backwards
  if (vexRT(Ch3) > 0 || vexRT(Ch2) > 0)
  {
    // moving forward
    // if the controller is less than 50 - then we should cut the motor power in half to control the slower movements better
    // check if zero before doing this (don't want to divide by zero - and it could have become zero by the time we reach this check)
    if (vexRT(Ch3) < 50 && vexRT(Ch3) > 0)
    {
       motor(LeftBaseBack) = vexRT(Ch3)/2;
       motor(LeftBaseFront) = vexRT(Ch3)/2;
    }
    if (vexRT(Ch2) < 50 && vexRT(Ch2) > 0)
    {
       motor(RightBaseBack) = vexRT(Ch2)/2;
       motor(RightBaseFront) = vexRT(Ch2)/2;
    }
    else
    {
       // joystick is past the 50 mark - so go full power requested
       motor(LeftBaseBack) = vexRT(Ch3);
       motor(LeftBaseFront) = vexRT(Ch3);
       motor(RightBaseBack) = vexRT(Ch2);
       motor(RightBaseFront) = vexRT(Ch2);
    }
  }
  else if (vexRT(Ch3) < 0 || vexRT(Ch2) < 0)
  {
    // moving backwards
    // if the controller is less than 50 - then we should cut the motor power in half to control the slower movements better
    // check if zero before doing this (don't want to divide by zero - and it could have become zero by the time we reach this check)
    if (vexRT(Ch3) > -50 && vexRT(Ch3) < 0)
    {
      motor(LeftBaseBack) = vexRT(Ch3)/2;
      motor(LeftBaseFront) = vexRT(Ch3)/2;
    }
    if (vexRT(Ch2) > -50 && vexRT(Ch2) < 0)
    {
      motor(RightBaseBack) = vexRT(Ch2)/2;
      motor(RightBaseFront) = vexRT(Ch2)/2;
    }
    else
    {
      // joystick is past the 50 mark - so go full power requested
      motor(LeftBaseBack) = vexRT(Ch3);
      motor(LeftBaseFront) = vexRT(Ch3);
      motor(RightBaseBack) = vexRT(Ch2);
      motor(RightBaseFront) = vexRT(Ch2);
    }
  }
  else
  {
    // not moving at all - set motors to zero
    motor(LeftBaseBack) = 0;
    motor(LeftBaseFront) = 0;
    motor(RightBaseBack) = 0;
    motor(RightBaseFront) = 0;
  }
}




// some sample code to help ramp the motors up in autonomous - given the speed 0 - 127) we want the robot to travel at, and the distance we want to go (encoder counts)
// this is a timed ramp routine - but as soon as we reach teh distance we are going we stop moving
void RampUp(int iSpeed, int iDistance)
{
  int pwr = 1;
  if (iSpeed > 0)
  {
    // moving forward
    for(int t = 1; t < iSpeed; t += 1)
    {
      // increment the power
      pwr = pwr + t;
      //set motors to pwr
      int iLE = abs(nMotorEncoder(LeftBaseBack));
      motor(LeftBaseBack) = pwr;
      motor(LeftBaseFront) = pwr;
      motor(RightBaseBack) = pwr;
      motor(RightBaseFront) = pwr;
      if (iLE > iDistance)
      {
        motor(LeftBaseBack) = 0;
        motor(LeftBaseFront) = 0;
        motor(RightBaseBack) = 0;
        motor(RightBaseFront) = 0;
        return;
      }
      if (pwr < 50)
      {
        // give the code a brief second to run at this speed before going up to the next speed - otherwise it ramps to fast and there is no noticeable affect
       	wait1Msec(100);
      }
    }
  }
  else if (iSpeed < 0)
  {
    // moving backwards
    for(int t = -1; t < iSpeed; t -= 1)
    {
      // increment the power
      pwr = pwr + t;
      //set motors to pwr
      int iLE = abs(nMotorEncoder(LeftBaseBack));
      motor(LeftBaseBack) = pwr;
      motor(LeftBaseFront) = pwr;
      motor(RightBaseBack) = pwr;
      motor(RightBaseFront) = pwr;
      if (iLE > iDistance)
      {
        motor(LeftBaseBack) = 0;
        motor(LeftBaseFront) = 0;
        motor(RightBaseBack) = 0;
        motor(RightBaseFront) = 0;
        return;
      }
      if (pwr < -50)
      {
        // give the code a brief second to run at this speed before going up to the next speed - otherwise it ramps to fast and there is no noticeable affect
       	wait1Msec(100);
      }
    }
  }
}